<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>统计同质子字符串的数目</title>
</head>
<body>
  <script>
    function fn(s) {
      let res = s[0];
      let ans = 0;
      for (let i = 0; i < s.length; i++) {
        res = s[i];
        ans++;
        for (let j = i + 1; j < s.length; j++) {
          if (s[j] === s[i]) {
            ans++;
          } else {
            break;
          }
        }
      }
      return ans;
    }
    console.log(fn('abbcccaa'))
  </script>
</body>
</html>